#ifndef STOCKIN_H
#define STOCKIN_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QComboBox>
#include <QTextEdit>
#include <QDateEdit>
#include <QIntValidator>
#include <QLabel>

class InventoryService;
class UserService;

class StockIn : public QWidget
{
    Q_OBJECT

public:
    explicit StockIn(const QMap<QString, QVariant> &userInfo, QWidget *parent = nullptr);
    ~StockIn();

private slots:
    void onReturnClicked();
    void onSaveClicked();
    void onCancelClicked();
    void onRefreshClicked();
    void onHistoryClicked();

private:
    void initUI();
    void setupStyles();

    // 布局控件
    QVBoxLayout *m_mainLayout;
    QHBoxLayout *m_topButtonLayout;
    QGridLayout *m_formLayout;
    QHBoxLayout *m_bottomButtonLayout;
    QWidget *m_formContainer;
    QFrame *m_shadowContainer;

    // 按钮控件
    QPushButton *m_btnReturn;
    QPushButton *m_btnSave;
    QPushButton *m_btnCancel;
    QPushButton *m_btnHistory;

    // 表单控件
    QLineEdit *m_edtInId;
    QComboBox *m_cmbCategory;
    QComboBox *m_cmbProduct;
    QLineEdit *m_edtCurrentStock; // 改为当前库存
    QLineEdit *m_edtSpecification;
    QLineEdit *m_edtPurchasePrice;
    QLineEdit *m_edtSupplier;
    QLineEdit *m_edtQuantity;
    QDateEdit *m_dateIn;
    QLineEdit *m_edtOperator;
    QTextEdit *m_edtNote;

    // 标题标签
    QLabel *m_lblTitle;

    QMap<QString, QVariant> m_currentUser; // 新增：存储当前用户信息

private:
    // 添加服务层对象
    InventoryService *m_inventoryService;
    UserService *m_userService;

    // 添加私有方法
    void loadCategories();
    void loadProductsByCategory(int categoryId);
    void updateProductInfo(int productId);
    void clearForm();

private slots:  // 通常这类回调函数会声明为槽函数
    void onCategoryChanged(int index);  // 添加声明
    void onProductChanged(int index);   // 添加声明
};

#endif // STOCKIN_H
